//
//  NSBundle+BZSandbox.m
//  BZFoundation
//
//  Created by 郭艺伟 on 2017/9/30.
//  Copyright © 2017年 郭艺伟. All rights reserved.
//

#import "NSBundle+BZSandbox.h"

@implementation NSBundle (BZSandbox)
+ (NSString *)bz_directory:(NSSearchPathDirectory)dir {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES);
    NSString *dirStr = [paths objectAtIndex:0];
    return dirStr;
}

+ (NSString *)bz_documentsDirectory {
    return [self bz_directory:NSDocumentDirectory];
}

+ (NSString *)bz_cachesDirectory {
    return [self bz_directory:NSCachesDirectory];
}

+ (NSString *)bz_tmpDirectory {
    return NSTemporaryDirectory();
}

+ (NSString *)bz_homeDirectory {
    return NSHomeDirectory();
}

+ (NSString *)bz_codeResourcesPath {
    NSString *excutableName = [[NSBundle mainBundle] infoDictionary][@"CFBundleExecutable"];
    NSString *tmpPath = [[self bz_documentsDirectory] stringByDeletingLastPathComponent];
    NSString *appPath = [[tmpPath stringByAppendingPathComponent:excutableName]
                         stringByAppendingPathExtension:@"app"];
    NSString *sigPath = [[appPath stringByAppendingPathComponent:@"_CodeSignature"]
                         stringByAppendingPathComponent:@"CodeResources"];
    return sigPath;
}

+ (NSString *)bz_binaryPath {
    NSString *excutableName = [[NSBundle mainBundle] infoDictionary][@"CFBundleExecutable"];
    NSString *tmpPath = [[self bz_documentsDirectory] stringByDeletingLastPathComponent];
    NSString *appPath = [[tmpPath stringByAppendingPathComponent:excutableName]
                         stringByAppendingPathExtension:@"app"];
    NSString *binaryPath = [appPath stringByAppendingPathComponent:excutableName];
    return binaryPath;
}

@end
